<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Code Prettifier</title>
<script type="text/javascript" src="prettify_test.js"></script>
<script type="text/javascript" src="test_base.js"></script>
<link rel="stylesheet" type="text/css" href="test_styles.css">
<script type="text/javascript">
(function () {
  // keep track of when window.onload fires, this is to make sure that we dont
  // miss it as it might occur before or after dynamic scripts are loaded
  var isReady = false;
  window.onload = function () { isReady = true; };

  // run tests when page is fully loaded
  function onReady() {
    runTests(goldens);
  }

  // JS & CSS prettify files to load
  var base = /[&?]loader\b/.test(location.search) ? '../loader/' : '../src/';
  var sources = [
    'lang-css.js',
    'lang-erlang.js',
    'lang-go.js',
    'lang-hs.js',
    'lang-lisp.js',
    'lang-lua.js',
    'lang-ml.js',
    'lang-proto.js',
    'lang-rust.js',
    'lang-scala.js',
    'lang-sql.js',
    'lang-vb.js',
    'lang-vhdl.js',
    'lang-wiki.js',
    'lang-yaml.js'
  ];
  var styles = [
    'prettify.css'
  ];

  // load skin(s)
  while (styles.length) {
    injectCSS(base + styles.shift());
  }

  // first load prettify.js
  injectJS(base + 'prettify.js', function () {
    // then load all lang-*.js concurrently
    while (sources.length) {
      injectJS(base + sources.shift(),
        (sources.length) ? undefined : function () {
          // then after last one is loaded, run tests when page is ready
          // (piggyback on window.onload if it hasn't already fired)
          if (isReady) {
            onReady();
          } else {
            window.onload = onReady;
          }
        });
    }
  });
})();
</script>
</head>

<body>
<h1>Test Results</h1>
<div id="report"></div>

<hr>

<h1>Bash</h1>
<pre class="prettyprint" id="bash">#!/bin/bash

# Fibonacci numbers
# Writes an infinite series to stdout, one entry per line
function fib() {
  local a=1
  local b=1
  while true ; do
    echo $a
    local tmp=$a
    a=$(( $a + $b ))
    b=$tmp
  done
}

# output the 10th element of the series and halt
fib | head -10 | tail -1
</pre>

<h1>Bash w/ language specified</h1>
<pre class="prettyprint lang-sh linenums" id="bash_lang">#!/bin/bash

# Fibonacci numbers
# Writes an infinite series to stdout, one entry per line
function fib() {
  local a=1
  local b=1
  while true ; do
    echo $a
    local tmp=$a
    a=$(( $a + $b ))
    b=$tmp
  done
}

# output the 10th element of the series and halt
fib | /usr/bin/*head -10 | tail -1
</pre>

<h1>Bash special characters</h1>
<p><a href="https://github.com/google/code-prettify/issues/165">Issue #165</a></p>
<pre class="prettyprint lang-sh" id="issue_165"># Comment
local $x = ${#x[@]}  # Previous is not a comment
# A comment</pre>

<h1>C</h1>
<pre class="prettyprint" id="c">
#include &lt;stdio.h&gt;

/* the n-th fibonacci number.
 */
unsigned int fib(unsigned int n) {
  unsigned int a = 1, b = 1;
  unsigned int tmp;
  while (--n &gt;= 0) {
    tmp = a;
    a += b;
    b = tmp;
  }
  return a;
}

main() {
  printf("%u", fib(10));
}
</pre>

<h1>C w/ language specified</h1>
<pre class="prettyprint lang-c" id="c_lang">
#include &lt;stdio.h&gt;

/* the n<sup>th</sup> fibonacci number. */
uint32 fib(unsigned int n) {
  uint32 a = 1, b = 1;
  uint32 tmp;
  while (--n &gt;= 0) {
    tmp = a;
    a += b;
    b = tmp;
  }
  return a;
}

void main() {
  size_t size = sizeof(wchar_t);
  ASSERT_EQ(size, 1);
  printf("%u", fib(10));
}

#define ZERO 0 /* a
  multiline comment */
</pre>

<h1>C++</h1>
<pre class="prettyprint" id="cpp">
#include &lt;iostream&gt;

using namespace std;

//! fibonacci numbers with gratuitous use of templates.
//! \param n an index into the fibonacci series
//! \param fib0 element 0 of the series
//! \return the nth element of the fibonacci series
template &lt;class T&gt;
T fib(unsigned int n, const T&amp; fib0) {
  T a(fib0), b(fib0);
  for (; n; --n) {
    T tmp(a);
    a += b;
    b = tmp;
  }
  return a;
}

int main(int argc, char **argv) {
  cout &lt;&lt; fib(10, 1U);
}
</pre>

<h1>C++ w/ language specified</h1>
<pre class="prettyprint lang-cc" id="cpp_lang">
#include &lt;iostream&gt;

using namespace std;

//! fibonacci numbers with gratuitous use of templates.
//! \param n an index into the fibonacci series
//! \param fib0 element 0 of the series
//! \return the nth element of the fibonacci series
template &lt;class T&gt;
T fib(int n, const T&amp; fib0) {
  T a(fib0), b(fib0);
  while (--n &gt;= 0) {
    T tmp(a);
    a += b;
    b = tmp;
  }
  return a;
}

int main(int argc, char **argv) {
  cout &lt;&lt; fib(10, 1U);
}
</pre>

<h1>Java</h1>
<pre class="prettyprint" id="java">
package foo;

import java.util.Iterator;

/**
 * the fibonacci series implemented as an Iterable.
 */
public final class Fibonacci implements Iterable&lt;Integer&gt; {
  /** the next and previous members of the series. */
  private int a = 1, b = 1;

  @Override
  public Iterator&lt;Integer&gt; iterator() {
    return new Iterator&lt;Integer&gt;() {
      /** the series is infinite. */
      public boolean hasNext() { return true; }
      public Integer next() {
        int tmp = a;
        a += b;
        b = tmp;
        return a;
      }
      public void remove() { throw new UnsupportedOperationException(); }
    };
  }

  /**
   * the n&lt;sup&gt;th&lt;/sup&gt; element of the given series.
   * @throws NoSuchElementException if there are less than n elements in the
   *   given Iterable's {@link Iterable#iterator iterator}.
   */
  public static &lt;T&gt;
  T nth(int n, Iterable&lt;T&gt; iterable) {
    Iterator&lt;? extends T&gt; it = iterable.iterator();
    while (--n &gt; 0) {
      it.next();
    }
    return it.next();
  }

  public static void main(String[] args) {
    System.out.print(nth(10, new Fibonacci()));
  }
}
</pre>

<h1>Java w/ language specified</h1>
<p>(first line shown is line 12)</p>
<pre class="prettyprint lang-java linenums:12" id="java_lang">
package foo;

import java.util.Iterator;

/**
 * the fibonacci series implemented as an Iterable.
 */
public final class Fibonacci implements Iterable&lt;Integer&gt; {
  /** the next and previous members of the series. */
  private int a = 1, b = 1;

  @Override
  public Iterator&lt;Integer&gt; iterator() {
    return new Iterator&lt;Integer&gt;() {
      /** the series is infinite. */
      public boolean hasNext() { return true; }
      public Integer next() {
        int tmp = a;
        a += b;
        b = tmp;
        return a;
      }
      public void remove() { throw new UnsupportedOperationException(); }
    };
  }

  /**
   * the n&lt;sup&gt;th&lt;/sup&gt; element of the given series.
   * @throws NoSuchElementException if there are less than n elements in the
   *   given Iterable's {@link Iterable#iterator iterator}.
   */
  public static &lt;T&gt;
  T nth(int n, Iterable&lt;T&gt; iterable) {
    Iterator&lt;? extends T&gt; in = iterable.iterator();
    while (--n &gt; 0) {
      in.next();
    }
    return in.next();
  }

  public static void main(String[] args) {
    System.out.print(nth(10, new Fibonacci()));
  }
}

# not a java comment
# not keywords: static_cast and namespace
</pre>

<h1>JavaScript</h1>
<pre class="prettyprint" id="javascript">
/**
 * nth element in the fibonacci series.
 * @param n &gt;= 0
 * @return the nth element, &gt;= 0.
 */
function fib(n) {
  var a = 1, b = 1;
  var tmp;
  while (--n &gt;= 0) {
    tmp = a;
    a += b;
    b = tmp;
  }
  return a;
}

document.write(fib(10));
</pre>

<h1>JavaScript Regular Expressions</h1>
<p><a href="https://github.com/google/code-prettify/issues/12">Issue #12</a></p>
<pre class="prettyprint" id="js_regexp">
/foo/;  // a slash starting a line treated as a regexp beginning
"foo".match(/fo+$/);
// this line comment not treated as a regular expressions
"foo /bar/".test(/"baz"/);  // test string and regexp boundaries
var division = /\b\d+\/\d+/g;  // test char sets and escaping of specials
var allSpecials = /([^\(\)\[\]\{\}\-\?\+\*\.\^\$\/]+)\\/;
var slashInCharset = /[^/]/g, notCloseSq = /[^\]]/;

// test that slash used in numeric context treated as an operator
1 / 2;
1. / x;
x / y;
(x) / y;
1 /* foo */ / 2;
1 /* foo *// 2;
1/2;
1./x;
x/y;
(x)/y;

// test split over two lines.  line comment should not fool it
1//
/2;

x++/y;
x--/y;
x[y] / z;
f() / n;

// test that slash after non postfix operator is start of regexp
log('matches = ' + /foo/.test(foo));

// test keyword preceders
return /a regexp/;
division = notreturn / not_a_regexp / 2;  // keyword suffix does not match

// &amp; not used as prefix operator in javascript but this should still work
&amp;/foo/;

extends = /extends/;
</pre>

<h1>JavaScript Regular Expressions w/ language specified</h1>
<p><a href="https://github.com/google/code-prettify/issues/12">Issue #12</a></p>
<pre class="prettyprint lang-js" id="js_regexp_lang">
/foo/;  // a slash starting a line treated as a regexp beginning
"foo".match(/fo+$/);
// this line comment not treated as a regular expressions
"foo /bar/".test(/"baz"/);  // test string and regexp boundaries
var division = /\b\d+\/\d+/g;  // test char sets and escaping of specials
var allSpecials = /([^\(\)\[\]\{\}\-\?\+\*\.\^\$\/]+)\\/;
var slashInCharset = /[^/]/g, notCloseSq = /[^\]]/;

// test that slash used in numeric context treated as an operator
1 / 2;
1. / x;
x / y;
(x) / y;
1 /* foo */ / 2;
1 /* foo *// 2;
1/2;
1./x;
x/y;
(x)/y;

// test split over two lines.  line comment should not fool it
1//
/2;

x++/y;
x--/y;
x[y] / z;
f() / n;

// test that slash after non postfix operator is start of regexp
log('matches = ' + /foo/.test(foo));

// test keyword preceders
return /a regexp/;
division = notreturn / not_a_regexp / 2;  // keyword suffix does not match

// &amp; not used as prefix operator in javascript but this should still work
&amp;/foo/;

extends = /extends/;
</pre>

<h1>CoffeeScript</h1>
<pre class="prettyprint lang-coffee" id="coffee">
class Animal
  constructor: (@name) -&gt;
  move: (meters, loc) -&gt;
    alert @name + " moved " + meters + "m."
  travel: (path...) -&gt;
    for place in path
      @move place.distance, place.location

class Horse extends Animal
  ###
  @param name Horse name
  @param jumper Jumping ability
  ###
  constructor: (name, jumper) -&gt;
    super name
    @capable = jumper
  step: -&gt;
    alert '''
          Step,
          step...
          '''
  jump: -&gt;
    @capable
  move: (meters, where) -&gt;
    switch where
      when "ground"
        @step()
        super meters
      when "hurdle"
        super meters if @jump()

# Create horse
tom = new Horse "Tommy", yes

street =
  location: "ground"
  distance: 12
car =
  location: "hurdle"
  distance: 2

###
Tell him to travel:
1. through the street
2. over the car
###
tom.travel street, car
</pre>

<h1>Perl</h1>
<pre class="prettyprint" id="perl">
#!/usr/bin/perl

use strict;
use integer;

# the nth element of the fibonacci series
# param n - an int &gt;= 0
# return an int &gt;= 0
sub fib($) {
  my $n = shift, $a = 1, $b = 1;
  ($a, $b) = ($a + $b, $a) until (--$n &lt; 0);
  return $a;
}

print fib(10);
</pre>

<h1>Python</h1>
<pre class="prettyprint" id="python">
#!/usr/bin/python2.4

def fib():
  '''
  a generator that produces the elements of the fibonacci series
  '''

  a = 1
  b = 1
  while True:
    a, b = a + b, a
    yield a

def nth(series, n):
  '''
  returns the nth element of a series,
  consuming the earlier elements of the series
  '''

  for x in series:
    n = n - 1
    if n &lt;= 0: return x

print nth(fib(), 10)
</pre>

<h1>Python w/ language specified</h1>
<pre class="prettyprint lang-py" id="python_lang">
#!/usr/bin/python2.4

def fib():
  '''
  a generator that produces the fibonacci series's elements
  '''

  a = 1
  b = 1
  while True:
    a, b = a + b, a
    yield a

def nth(series, n):
  '''
  returns the nth element of a series,
  consuming the series' earlier elements.
  '''

  for x in series:
    n -= 1
    if n &lt;= 0: return x

print nth(fib(), 10)

/* not a comment and not keywords: null char true */
</pre>

<h1>SQL</h1>
<pre class="prettyprint lang-sql" id="sql_lang">
/* A multi-line
 * comment */
'Another string /* Isn\'t a comment',
"A string */"
-- A line comment
SELECT * FROM users WHERE id IN (1, 2.0, +30e-1);
-- keywords are case-insensitive.
-- Note: user-table is a single identifier, not a pair of keywords
select * from user-table where id in (x, y, z);
</pre>

<h1>XML</h1>
<pre class="prettyprint" id="xml">
&lt;!DOCTYPE series PUBLIC "fibonacci numbers"&gt;

&lt;series.root base="1" step="s(n-2) + s(n-1)"&gt;
  &lt;element i="0"&gt;1&lt;/element&gt;
  &lt;element i="1"&gt;1&lt;/element&gt;
  &lt;element i="2"&gt;2&lt;/element&gt;
  &lt;element i="3"&gt;3&lt;/element&gt;
  &lt;element i="4"&gt;5&lt;/element&gt;
  &lt;element i="5"&gt;8&lt;/element&gt;
  ...
&lt;/series.root&gt;
</pre>

<h1>HTML</h1>
<pre class="prettyprint" id="html">
&lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;Fibonacci number&lt;/title&gt;
    &lt;style&gt;&lt;!-- BODY { text-decoration: blink } --&gt;&lt;/style&gt;
    &lt;script src="foo.js"&gt;&lt;/script&gt;
    &lt;script src="bar.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;noscript&gt;
      &lt;dl&gt;
        &lt;dt&gt;Fibonacci numbers&lt;/dt&gt;
        &lt;dd&gt;1&lt;/dd&gt;
        &lt;dd&gt;1&lt;/dd&gt;
        &lt;dd&gt;2&lt;/dd&gt;
        &lt;dd&gt;3&lt;/dd&gt;
        &lt;dd&gt;5&lt;/dd&gt;
        &lt;dd&gt;8&lt;/dd&gt;
        &amp;hellip;
      &lt;/dl&gt;
    &lt;/noscript&gt;

    &lt;script type="text/javascript"&gt;&lt;!--
function fib(n) {
  var a = 1, b = 1;
  var tmp;
  while (--n &gt;= 0) {
    tmp = a;
    a += b;
    b = tmp;
  }
  return a;
}

document.writeln(fib(10));
// --&gt;
    &lt;/script&gt;
  &lt;/body&gt;
&lt;/html&gt;
</pre>

<h1>HTML w/ language specified</h1>
<pre class="prettyprint lang-html" id="html_lang">
Fibonacci Numbers

&lt;noscript&gt;
  &lt;dl style="list-style: disc"&gt;
    &lt;dt&gt;Fibonacci numbers&lt;/dt&gt;
    &lt;dd&gt;1&lt;/dd&gt;
    &lt;dd&gt;1&lt;/dd&gt;
    &lt;dd&gt;2&lt;/dd&gt;
    &lt;dd&gt;3&lt;/dd&gt;
    &lt;dd&gt;5&lt;/dd&gt;
    &lt;dd&gt;8&lt;/dd&gt;
    &amp;hellip;
  &lt;/dl&gt;
&lt;/noscript&gt;

&lt;script type="text/javascript"&gt;&lt;!--
function fib(n) {
  var a = 1, b = 1;
  var tmp;
  while (--n &gt;= 0) {
    tmp = a;
    a += b;
    b = tmp;
  }
  return a;
}

document.writeln(fib(10));
// --&gt;
&lt;/script&gt;
</pre>

<h1>HTML using &lt;XMP&gt;</h1>
<xmp class="prettyprint" id="html_xmp"
><html>
  <head>
    <title>Fibonacci number</title>
  </head>
  <body>
    <noscript>
      <dl>
        <dt>Fibonacci numbers</dt>
        <dd>1</dd>
        <dd>1</dd>
        <dd>2</dd>
        <dd>3</dd>
        <dd>5</dd>
        <dd>8</dd>
        &hellip;
      </dl>
    </noscript>

    <script type="text/javascript"><!--
function fib(n) {
  var a = 1, b = 1;
  var tmp;
  while (--n >= 0) {
    tmp = a;
    a += b;
    b = tmp;
  }
  return a;
}

document.writeln(fib(10));
// -->
    </script>
  </body>
</html>
</xmp>

<h1>XHTML</h1>
<pre class="prettyprint" id="xhtml"
>&lt;xhtml&gt;
  &lt;head&gt;
    &lt;title&gt;Fibonacci number&lt;/title&gt;
  &lt;/head&gt;
  &lt;body onload="alert(fib(10))"&gt;
    &lt;script type="text/javascript"&gt;&lt;![CDATA[
function fib(n) {
  var a = 1, b = 1;
  var tmp;
  while (--n &gt;= 0) {
    tmp = a;
    a += b;
    b = tmp;
  }
  return a;
}
]]&gt;
    &lt;/script&gt;
  &lt;/body&gt;
&lt;/xhtml&gt;
</pre>

<h1>PHP</h1>
<pre class="prettyprint" id="php">
&lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;&lt;?= 'Fibonacci numbers' ?&gt;&lt;/title&gt;

    &lt;?php
      // PHP has a plethora of comment types
      /* What is a
         "plethora"? */
      function fib($n) {
        # I don't know.
        $a = 1;
        $b = 1;
        while (--$n &gt;= 0) {
          echo "$a\n";
          $tmp = $a;
          $a += $b;
          $b = $tmp;
        }
      }
    ?&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;?= fib(10) ?&gt;
  &lt;/body&gt;
&lt;/html&gt;
</pre>

<h1>XSL</h1>
<p><a href="https://github.com/google/code-prettify/issues/19">Issue #19</a></p>
<pre class="prettyprint" id="xsl">
&lt;!-- Test elements and attributes with namespaces --&gt;

&lt;xsl:stylesheet xml:lang="en"&gt;
  &lt;xsl:template match="."&gt;
    &lt;xsl:text&gt;Hello World&lt;/xsl:text&gt;
  &lt;/xsl:template&gt;
&lt;/xsl:stylesheet&gt;
</pre>

<h1>Whitespace</h1>
<pre class="prettyprint" id="whitespace"></pre>

<h1>Misc</h1>
<pre class="prettyprint" id="misc1">// ends with line comment token
//</pre>

<h1>JavaScript inside HTML &lt;SCRIPT&gt;</h1>
<p>
<a href="https://github.com/google/code-prettify/issues/4">Issue #4</a>:
JavaScript Snippets wrapped in HTML SCRIPT tags hides/destroys inner content
</p>
<p>The fact that the script tag was not closed properly was causing
<em>PR_splitSourceNodes</em> to end without emitting the script contents.</p>
<pre class="prettyprint" id="js_script">
&lt;script type="text/javascript"&gt;
   var savedTarget=null;                           // The target layer (effectively vidPane)
   var orgCursor=null;                             // The original mouse style so we can restore it
   var dragOK=false;                               // True if we're allowed to move the element under mouse
   var dragXoffset=0;                              // How much we've moved the element on the horozontal
   var dragYoffset=0;                              // How much we've moved the element on the verticle
   vidPaneID = document.getElementById('vidPane'); // Our movable layer
   vidPaneID.style.top='75px';                     // Starting location horozontal
   vidPaneID.style.left='75px';                    // Starting location verticle
&lt;script&gt;
</pre>

<h1>Tabs mangled</h1>
<p><a href="https://github.com/google/code-prettify/issues/8">Issue #8</a>:
If tabs are used to indent code inside &lt;pre&gt;, IE6 and 7 won't honor them
after the script runs.</p>
<p>Code indented with tabs will be shown aligned to the left margin instead of
the proper indenting shown in Firefox.</p>
<p>I'm using Revision 20 of prettify.js, IE 6.0.29.00 in English and IE
7.0.5730.11 in Spanish.</p>
<pre class="prettyprint" id="issue8">
<b>one</b>&#9;<b>Two</b>&#9;<b>three</b>&#9;Four&#9;<b>five</b>&#9;|
Six&#9;<b>seven</b>&#9;Eight&#9;nine&#9;Ten&#9;|
<b>eleven</b>&#9;Twelve&#9;<b>thirteen</b>&#9;Fourteen&#9;fifteen&#9;|
</pre>

<h1>Does not recognize <code>&lt;br&gt;</code> as newline</h1>
<p><a href="https://github.com/google/code-prettify/issues/14">Issue #14</a></p>
<pre class="prettyprint" id="issue14a"
>//comment<br />int main(int argc, char **argv)
{}</pre>

<h1>Comments not ignored</h1>
<p><a href="https://github.com/google/code-prettify/issues/14">Issue #14</a></p>
<pre class="prettyprint" id="issue14b"
>&lt;!-- There's an <!-- BOO!! --><acronym title="tag soup">HTML</acronym> comment in my comment --&gt;
&lt;p&gt;And another one inside the end tag&lt;/p<!-- GOTCHA!! -->&gt;
</pre>

<h1>Missing blank lines</h1>
<p><a href="https://github.com/google/code-prettify/issues/20">Issue #20</a></p>
<pre class="prettyprint" id="issue20"
>&lt;html&gt;

&lt;head&gt;</pre>

<h1>Code doesn't copy and paste well in IE</h1>
<p><a href="https://github.com/google/code-prettify/issues/21">Issue #21</a>:
To test this bug, disable overriding of <em>_pr_isIE6</em> in test_base.js
by putting <em>#testcopypaste</em> on the end of the URL and reloading the
page, then copy and paste the above into Notepad.</p>
<pre class="prettyprint" id="issue21"
>&lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;Test&lt;/title&gt;
  &lt;/head&gt;
&lt;/html&gt;</pre>

<h1>Line numbers and other non-code spans in code</h1>
<p><a href="https://github.com/google/code-prettify/issues/22">Issue #22</a></p>
<pre class="prettyprint lang-java" id="issue22"
><span class="nocode">01: </span>// This is a line of code
<span class="nocode">02: </span>/* Multiline comments can
<span class="nocode">03: </span> * span over and around
<span class="nocode">04: </span> * line markers
<span class="nocode annot">And can even be interrupted</span>
<span class="nocode annot">by inline code annotations</span>
<span class="nocode">05: </span> */
<span class="nocode">06: </span>class MyClass extends Foo {
<span class="nocode">07: </span>  public static void main(String... argv) {
<span class="nocode">08: </span>    System.out.print("Hello World");
<span class="nocode">09: </span>  }
<span class="nocode">10: </span>}</pre>

<h1>Lua</h1>
<p><a href="https://github.com/google/code-prettify/issues/24">Issue #24</a></p>
<pre class="prettyprint lang-lua" id="lua">
os=require("os")
math=require("math")

-- Examples from the language reference
     a = 'alo\n123"'
     a = "alo\n123\&quot;"
     a = '\97lo\10\04923"'
     a = [[alo
     123&quot;]]
     a = [==[
     alo
     123&quot;]==]

3   3.0   3.1416   314.16e-2   0.31416E1   0xff   0x56

-- Some comments that demonstrate long brackets
double_quoted = "Not a long bracket [=["
--[=[ quoting out
 [[ foo ]]
 [==[does not end comment either]==]
]=]
past_end_of_comment
--]=]

-- Example code courtesy Joseph Harmbruster
#
do
  local function ssgeneral(t, n, before)
    for _, h in ipairs(incs) do
      for i = h + 1, n do
        local v = t[i]
        for j = i - h, 1, -h do
          local testval = t[j]
          if not before(v, testval) then break end
          t[i] = testval; i = j
        end
        t[i] = v
      end 
    end
    return t
  end

  function shellsort(t, before, n)
    n = n or #t
    if not before or before == "&lt;" then return ssup(t, n)
    elseif before == "&gt;" then return ssdown(t, n)
    else return ssgeneral(t, n, before)
    end
  end
  return shellsort
end</pre>

<h1>VBScript</h1>
<p><a href="https://github.com/google/code-prettify/issues/27">Issue #27</a></p>
<pre class="prettyprint lang-vb" id="vbs">
Imports System

Class [class]
    Shared Sub [shared](ByVal [boolean] As Boolean)
        If [boolean] Then
            Console.WriteLine("true")
        Else
            Console.WriteLine("false")
        End If
    End Sub
End Class

' Comment
&#x2018; Second Line comment with a smart quote _
  continued line using VB6 syntax.
Module [module]
    Sub Main()
        [class].[shared](True)

        ' This prints out: &quot;.
        Console.WriteLine("""")

        ' This prints out: a&quot;b.
        Console.WriteLine("a""b")

        ' This prints out: a.
        Console.WriteLine("a"c)

        ' This prints out: &quot;.
        Console.WriteLine(""""c)

        REM an old-style comment
        REMOVE(not_a_comment)
    End Sub
End Module

Dim d As Date
d = # 8/23/1970 3:45:39AM #
d = # 8/23/1970 #
d = # 3:45:39AM #
d = # 3:45:39 #
d = # 13:45:39 #
d = # 13:45:39PM #

Dim n As Float
n = (0.0, .99F, 1.0E-2D, 1.0E+3D, .5E4, 1E3R, 4D)

Dim i As Integer
i = (0, 123, 45L, &amp;HA0I, &amp;O177S)
</pre>

<h1>Haskell</h1>
<p><a href="https://github.com/google/code-prettify/issues/30">Issue #30</a></p>
<pre class="prettyprint lang-hs" id="haskell">
-- A comment
Not(--"a comment&quot;)
Also.not(--(A.comment))

module Foo(bar) where
import Blah
import BlahBlah(blah)
import Monads(Exception(..), FIO(..),unFIO,handle,runFIO,fixFIO,fio,
              write,writeln,HasNext(..),HasOutput(..))

{- nested comments
 - don't work {-yet-} -}
instance Thingy Foo where
  a = b

data Foo :: (* -&gt; * -&gt; *) -&gt; * &gt; * -&gt; * where
  Nil :: Foo a b c
  Cons :: a b c -&gt; Foo abc -&gt; Foo a b c

str = &quot;Foo\\Bar"
char = 'x'
Not.A.Char = 'too long'  -- Don't barf.  Show that 't is a lexical error.

(ident, ident', Fo''o.b'ar)

(0, 12, 0x45, 0xA7, 0o177, 0O377, 0.1, 1.0, 1e3, 0.5E-3, 1.0E+45)
</pre>

<h1>OCaml and F#</h1>
<p><a href="https://github.com/google/code-prettify/issues/33">Issue #33</a></p>
<p>TODO: handle nested <code>(* (* comments *) *)</code> properly.</p>
<pre class="prettyprint lang-ml" id="ml">
(*
 * Print the 10th fibonacci number
 *)

//// A line comment
"A string";;
(0, 125, 0xa0, -1.0, 1e6, 1.2e-3);;  // number literals

#if fibby
  let
    rec fib = function (0, a, _) -&gt; a
                     | (n, a, b) -&gt; fib(n - 1, a + b, a)
  in
    print_int(fib(10, 1, 1));;
#endif

let zed = 'z'

let f' x' = x' + 1
</pre>

<h1>Lisp</h1>
<p><a href="https://github.com/google/code-prettify/issues/42">Issue #42</a></p>
<pre class="prettyprint lang-el" id="lisp"
>; -*- mode: lisp -*-

(defun back-six-lines () (interactive) (forward-line -6))
(defun forward-six-lines () (interactive) (forward-line 6))

(global-set-key "\M-l" 'goto-line)
(global-set-key "\C-z" 'advertised-undo)
(global-set-key [C-insert] 'clipboard-kill-ring-save)
(global-set-key [S-insert] 'clipboard-yank)
(global-set-key [C-up] 'back-six-lines)
(global-set-key [C-down] 'forward-six-lines)

(setq visible-bell t)
(setq user-mail-address "foo@bar.com")
(setq default-major-mode 'text-mode)

(setenv "TERM" "emacs")
(c-set-offset 'case-label 2)
(setq c-basic-offset 2)
(setq perl-indent-level 0x2)
(setq delete-key-deletes-forward t)
(setq indent-tabs-mode nil)

;; Text mode
(add-hook 'text-mode-hook 
  '(lambda ()
     (turn-on-auto-fill)
   )
)

;; Fundamental mode
(add-hook 'fundamental-mode-hook 
  '(lambda ()
     (turn-on-auto-fill)
   )
)

;; Define and cond are keywords in scheme
(define (sqt x) (sqrt-iter 1.0 2.0 x))
</pre>

<h1>Square brackets in strings</h1>
<p><a href="https://github.com/google/code-prettify/issues/45">Issue #45</a></p>
<pre class="prettyprint" id="issue45">
throw new RuntimeException("Element [" + element.getName() + 
  "] missing attribute.");
variable++;
</pre>

<h1>Protocol Buffers</h1>
<pre class="prettyprint lang-proto" id="proto"
>message SearchRequest {
  required string query = 1;
  optional int32 page_number = 2;
  optional int32 result_per_page = 3 [default = 10];
  enum Corpus {
    UNIVERSAL = 0;
    WEB = 1;
    IMAGES = 2;
    LOCAL = 3;
    NEWS = 4;
    PRODUCTS = 5;
    VIDEO = 6;
  }
  optional Corpus corpus = 4 [default = UNIVERSAL];
}</pre>

<h1>Wiki Syntax</h1>
<pre class="prettyprint lang-wiki" id="wiki">
#summary hello world
#labels HelloWorld WikiWord Hiya

[http://www.google.com/?q=WikiSyntax+site:code.google.com WikiSyntax]

Lorem Ipsum `while (1) print("blah blah");`

   * Bullet
   * Points
      * NestedBullet

==DroningOnAndOn==
{{{
  // Some EmbeddedSourceCode
  void main() {
    Print('hello world');
  }
}}}

{{{
  &lt;!-- Embedded XML --&gt;
  &lt;foo bar="baz"&gt;&lt;boo /&gt;&lt;foo&gt;
}}}
</pre>

<h1>CSS w/ language specified</h1>
<pre class="prettyprint lang-css" id="css">
&lt;!--
@charset('UTF-8');

/** A url that is not quoted. */
@import(url(/more-styles.css));

HTML { content-before: 'hello\20'; content-after: 'w\6f rld';
       -moz-spiff: inherit !important }

/* Test units on numbers. */
BODY { margin-bottom: 4px; margin-left: 3in; margin-bottom: 0; margin-top: 5% }

/** Test number literals and quoted values. */
TABLE.foo TR.bar A#visited { color: #001123; font-family: "monospace" }
/** bolder is not a name, so should be plain.  !IMPORTANT is a keyword
  * regardless of case.
  */
blink { text-decoration: BLINK !IMPORTANT; font-weight: bolder }
/* Empty url() was causing infinite recursion */
a { background-image: url(); }
p#featured{background:#fea}
--&gt;
</pre>

<h1>CSS inside HTML &lt;STYLE&gt;</h1>
<p><a href="https://github.com/google/code-prettify/issues/79">Issue #79</a></p>
<pre class="prettyprint" id="css_style">
&lt;style type='text/css'&gt;
/* desert scheme ported from vim to google prettify */
code.prettyprint { display: block; padding: 2px; border: 1px solid #888;
background-color: #333; }
.str { color: #ffa0a0; } /* string  - pink */
.kwd { color: #f0e68c; font-weight: bold; }
.com { color: #87ceeb; } /* comment - skyblue */
.typ { color: #98fb98; } /* type    - lightgreen */
.lit { color: #cd5c5c; } /* literal - darkred */
.pun { color: #fff; }    /* punctuation */
.pln { color: #fff; }    /* plaintext */
.tag { color: #f0e68c; font-weight: bold; } /* html/xml tag    - lightyellow*/
.atn { color: #bdb76b; font-weight: bold; } /* attribute name  - khaki*/
.atv { color: #ffa0a0; } /* attribute value - pink */
.dec { color: #98fb98; } /* decimal         - lightgreen */
&lt;/style&gt;
</pre>

<h1>NBSPs</h1>
<p><a href="https://github.com/google/code-prettify/issues/84">Issue #84</a></p>
<pre class="prettyprint lang-java" id="issue84">super("&amp;nbsp;");</pre>

<h1>Line breaks and preformatted style</h1>
<p><a href="https://github.com/google/code-prettify/issues/86">Issue #86</a></p>
<p>CODE tag</p>
<p><code class="prettyprint" id="issue86_0">#One
Two words</code></p>
<p>CODE tag with preformatted style</p>
<p><code class="prettyprint known_ie6_failure" id="issue86_1" style="white-space: pre">#One
Two lines</code></p>
<p>PRE tag</p>
<pre class="prettyprint" id="issue86_2">#One
Two lines</pre>
<p>PRE+CODE tag</p>
<pre><code class="prettyprint known_ie6_failure" id="issue86_3">#One
Two lines</code></pre>
<p>XMP tag</p>
<xmp class="prettyprint" id="issue86_4">#One
Two lines</xmp>
<p>CODE tag with BR line break</p>
<p><code class="prettyprint" id="issue86_5">#One<br>
Two lines</code></p>

<h1>Capital letters in tag names</h1>
<p><a href="https://github.com/google/code-prettify/issues/92">Issue #92</a></p>
<pre class="prettyprint" id="issue92">
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;kml xmlns="http://www.opengis.net/kml/2.2"&gt;
  &lt;Placemark&gt;
    &lt;name&gt;Simple placemark&lt;/name&gt;
    &lt;description Lang="en"&gt;Attached to the ground. Intelligently places itself 
       at the height of the underlying terrain.&lt;/description&gt;
    &lt;Point&gt;
      &lt;coordinates&gt;-122.0822035425683,37.42228990140251,0&lt;/coordinates&gt;
    &lt;/Point&gt;
  &lt;/Placemark&gt;
&lt;/kml&gt;
</pre>

<h1>C# verbatim strings</h1>
<p><a href="https://github.com/google/code-prettify/issues/93">Issue #93</a></p>
<pre class="prettyprint lang-cs" id="cs_verbatim">
// The normal string syntax
string a = "C:\\";
// is equivalent to a verbatim string
string b = @"C:\";
</pre>

<h1>VHDL</h1>
<pre class="prettyprint lang-vhdl" id="vhdl">
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

-- A line comment
entity foo_entity is

  generic (-- comment after punc
    a : natural := 42;
    x : real := 16#ab.cd#-3
  );
  port (
    clk_i : in  std_logic;
    b_i   : in  natural range 0 to 100;
    c_o   : out std_logic_vector(5 downto 0);
    \a "name"\ : out integer  -- extended identifier
  );

end entity foo_entity;

architecture foo_architecture of foo_entity is
  signal bar_s : std_logic_vector(2 downto 0);
begin
  
  bar_s &lt;= b"101";

  dummy_p : process (clk_i)
  begin
    if b_i = 1 then
      c_o &lt;= (others =&gt; '0');
    elsif rising_edge(clk_i) then
      c_o &lt;= "1011" &amp; bar_s(1 downto 0);
    end if;
  end process dummy_p;

end architecture foo_architecture;
</pre>

<h1>YAML</h1>
<pre class="prettyprint lang-yaml" id="yaml1">
application: mirah-lang
version: 1

# Here's a comment
handlers:
  - url: /red/*
     servlet: mysite.server.TeamServlet
     init_params:
       teamColor: red
       bgColor: "#CC0000"
     name: redteam
  - url: /blue/*
     servlet: mysite.server.TeamServlet
     init_params:
       teamColor: blue
       bgColor: "#0000CC"
     name: blueteam
  - url: /register/*
     jsp: /register/start.jsp
  - url: *.special
     filter: mysite.server.LogFilterImpl
     init_params:
       logType: special
  </pre>

<h1>YAML</h1>
<pre class="prettyprint lang-yaml" id="yaml2">
%YAML 1.1
---
!!map {
  ? !!str ""
  : !!str "value",
  ? !!str "explicit key"
  : !!str "value",
  ? !!str "simple key"
  : !!str "value",
  ? !!seq [
    !!str "collection",
    !!str "simple",
    !!str "key"
  ]
  : !!str "value"
}</pre>

<h1>Scala</h1>
<pre class="prettyprint lang-scala" id="scala">
/* comment 1 */
/*
comment 2
*/
/* comment / * comment 3 **/
// strings
"Hello, World!", "\n",
`an-identifier`, `\n`,
'A', '\n',
'aSymbol,
"""Hello,
World""", """Hello,\nWorld""",
"""Hello, "World"!""",
"""Hello, \"World\""""

// Numbers
0
0123
0xa0
0XA0L
123
123.45
1.50F
0.50
.50
123e-1
123.45e+1
1.50e2
0.50e-6
.50e+42f

// Values
false, true, null, this;

// Keywords
class MyClass;
import foo.bar;
package baz;

// From scala-lang.org/node/242
def act() {
  var pongCount = 0
  loop {
    react {
      case Ping =&gt;
        if (pongCount % 1000 == 0)
          Console.println("Pong: ping "+pongCount)
        sender ! Pong
        pongCount = pongCount + 1
      case Stop =&gt;
        Console.println("Pong: stop")
        exit()
    }
  }
}
</pre>

<h1>Go</h1>
<pre class="prettyprint lang-go" id="go">
package main  /* Package of which this program is part. */

import fmt "fmt"  // Package implementing formatted I/O.


func main() {
    fmt.Printf("Hello, world; or &#x039a;&#x03b1;&#x03bb;&#x03b7;&#x03bc;&#x03ad;&#x03c1;&#x03b1; &#x03ba;&#x03cc;&#x03c3;&#x03bc;&#x03b5;; or &#x3053;&#x3093;&#x306b;&#x3061;&#x306f; &#x4e16;&#x754c;\n")  // Semicolon inserted here
}

/* " */  &quot;foo /* "  /*/  */
/* ` */  `foo /* `  /*/  */
</pre>

<h1>Erlang</h1>
<pre class="prettyprint lang-erlang" id="erlang">
% Sample comment

-module(my_test).
-include_lib("my_sample_lib.hrl").
-export([
    test/2
]).

%% @doc Define a macro
-define(my_macro, Variable).

%% @doc My function
test(Variables, MoreVariables) -&gt;
    % Inline comment
    {ok,Scanned,_} = my_lib:do_stuff(),

    Variable = fun(V) -&gt; {ok, V} end,

    try ?my_macro({value, test}) of
        {value, Result, _} -&gt;
            {ok, Result}
    catch
        Type:Error -&gt;
            {'error', Type, Error}
    end.
</pre>

<h1>Rust</h1>
<pre class="prettyprint lang-rust" id="rust">
// Single line comment
/* Multi-line (nesting not highlighted properly, sorry)
comment */

#![feature(code_prettification)]

use std::io::{self, Write};

impl&lt;'a, T: 'a + ?Sized&gt; Foo&lt;'a, 'static&gt; for Bar&lt;'b&gt;
where T: Iterator&lt;Item = Box&lt;Fn() -&gt; u32&gt;&gt; {
    fn something(&amp;mut self) -&gt; u32 {
        if let Some(ref x) = self.foo("multi li\ne
s\tring") {
            panic!(r"\things is going wrong!");
            panic!(r#"Things is "really" goig\n wront!"#);
            panic!(r##"Raw strings are #"#fancy#"#"##);
        }
    }
}

pub type CowString&lt;'a&gt; = std::cow::Cow&lt;'a, str&gt;;

fn main() {
    let (i, r) = (1u8, 'c');
    let s = r#"Take a raw egg,
        "break" it (or the line),
        and beat it"#;
}
</pre>

</body>
</html>
